<template>
  <div class="app-container">
    <el-dialog title="图纸选择"
               v-if="showFlag"
               :visible.sync="showFlag"
               :modal=false
               width="80%"
               center
    >
    <el-card style="border-radius: 10px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="单据日期">
        <el-date-picker
          v-model="daterangeIssueDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="汇报人" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入汇报人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单客户" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入订单客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="工单编号" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部件名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入部件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部件图号" prop="drawingNumber">
        <el-input
          v-model="queryParams.drawingNumber"
          placeholder="请输入部件图号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异常描述" prop="issueDescription">
        <el-input
          v-model="queryParams.issueDescription"
          placeholder="请输入异常描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <el-card style="border-radius: 10px;margin-top: 15px">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table border v-loading="loading" :data="reportList" border @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column width="55" align="center">
        <template v-slot="scope">
          <el-radio v-model="selectedId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{ "" }}</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="汇报单编号" align="center" prop="reportCode" />
      <el-table-column label="单据日期" align="center" prop="issueDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.issueDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="汇报人" align="center" prop="nickName" />
      <el-table-column label="订单客户" align="center" prop="customerName" />
      <el-table-column label="生产工单" align="center" prop="workorderCode" />
      <el-table-column label="部件名称" align="center" prop="itemName" />
      <el-table-column label="部件图号" align="center" prop="drawingNumber" />
      <el-table-column label="部件规格" align="center" prop="specification" />
      <el-table-column label="异常数量" align="center" prop="quantity" />
      <el-table-column label="异常描述" :show-overflow-tooltip="true" align="center" prop="issueDescription" >

      </el-table-column>
      <el-table-column label="状态" align="center" prop="flowStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.flow_status" :value="scope.row.flowStatus"/>
        </template>
      </el-table-column>

<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['col:report:query']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.flowStatus==9"
            v-hasPermi="['col:report:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['col:report:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="selectCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReport, getReport, delReport, addReport, updateReport } from "@/api/mes/col/report";
import {getMdItem} from "@/api/mes/md/mdItem"


export default {
  name: "Report",
  dicts: ['flow_status'],
  data() {
    return {
      showFlag:false,
      selectedId: null,
      selectedRow: null,
      // 遮罩层
      loading: true,
      otherStatus: "DIED",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      optType: undefined,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 问题上报表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户昵称时间范围
      daterangeIssueDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        drawingNumber: null,        issueDescription: null,        issueDate: null,        itemName: null,        workorderCode: null,        customerName: null,
        nickName: null      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        issueDescription: [
          { required: true, message: "异常描述不能为空", trigger: "blur" }
        ],        issueDate: [
          { required: true, message: "单据日期不能为空", trigger: "blur" }
        ],        quantity: [
          { required: true, message: "异常部件数量不能为空", trigger: "blur" }
        ],        workorderCode: [
          { required: true, message: "生产工单不能为空", trigger: "blur" }
        ],      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询问题上报列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeIssueDate && '' != this.daterangeIssueDate) {
        this.queryParams.params["beginIssueDate"] = this.daterangeIssueDate[0];
        this.queryParams.params["endIssueDate"] = this.daterangeIssueDate[1];
      }
      listReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRow = row;
        this.$emit('onSelected', this.selectedRow);
        this.showFlag = false;
        this.selectedId = null;
        this.selectedRow = null;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    selectCancel(){
      this.showFlag = false
      this.selectedId = null
      this.selectedRow = null
    },
    //确定选中
    confirmSelect() {
      if (this.selectedId == null || this.selectedId == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRow);
      this.showFlag = false;
      this.selectedId = null;
      this.selectedRow = null;

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
    drawingNumber: null,
        issueDescription: null,        issueDate: new Date(),        itemCode: null,        itemName: null,        specification: null,        quantity: null,
    taskId:null,    taskCode: null,        workorderCode: null,  workorderId: null,      customerName: null,
          flowStatus: "0"
            };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.selectedId = null
      this.selectedRow = null
      this.daterangeIssueDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    handleView(row){
      this.getReportDetail(row.id ,'view',"查看问题上报")
    },


  }
};
</script>
